<!DOCTYPE html>
<!--
 Copyright (c)2024 Oracle and/or its affiliates.
 Licensed under The Universal Permissive License (UPL), Version 1.0
 as shown at https://oss.oracle.com/licenses/upl/
 -->
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CloudBank - New Account</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript">
        function showErrorModal(username) {
            document.getElementById('generatedUsername').innerText = username;
            $('#usernameModal').modal('show');
        }
    </script>
    <style>
        body {
            background-color: #f0f0f0;
        }
        /* Oracle's primary color */
        
        .navbar-custom {
            background-color: #f80000d0;
        }
        
        .navbar-custom .navbar-brand,
        .navbar-custom .nav-link,
        .navbar-custom .btn-logout {
            color: #ffffff;
        }
        
        .account-card {
            background-color: #ffffff;
            margin-top: 20px;
            padding: 15px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
        }
        
        .divider {
            border-top: 1px solid #ccc;
            margin: 10px 0;
        }
        
        .account-info {
            font-size: 18px;
        }
        
        .balance {
            font-weight: bold;
            font-size: 22px;
        }
        
        .credit-score-card {
            text-align: center;
            background-color: #ffffff;
            margin-top: 30px;
            padding: 15px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
        }
        
        .ml-auto {
            margin-left: auto;
        }
    </style>
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar-custom">
        <a class="navbar-brand" href="#">
            <img src="{{ url_for('static', filename='images/oracle-blk.png') }}" alt="Oracle Logo" style="height: 30px; margin-right: 20px;"> CLOUDBANK
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
            <i class="fas fa-arrow-down" style="color: black;"></i> 
        </button>
        <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
            <div class="navbar-nav">
                <a class="nav-item nav-link" href="{{ url_for('dashboard') }}">Home</a>
                <a class="nav-item nav-link" href="{{ url_for('transfer') }}">Transfer</a>
                <a class="nav-item nav-link" href="{{ url_for('account_details') }}">Account</a>
            </div>
            <button class="btn btn-outline-light btn-logout ml-auto" onclick="location.href='/logout'">Logout</button>
        </div>
    </nav>

    <!-- Modal -->
    <div class="modal fade" id="usernameModal" tabindex="-1" aria-labelledby="usernameModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="usernameModalLabel">Account Creation Error</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
                </div>
                <div class="modal-body">
                    <span id="generatedUsername"></span>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
    {% if error %}
    <script type="text/javascript">
        showErrorModal('{{ error }}');
    </script>
    {% endif %}

    <div class="container mt-5">
        <h2>Apply for New Bank Account / Credit Card</h2>
        <form action="{{ url_for('create_bank_account') }}" method="post" id="accountForm">
            <div class="form-group">
                <label for="account_type">Select Type:</label>
                <select id="account_type" name="account_type" class="form-control" onchange="showSubTypeAndEnableSubmit(this.value)">
                    <option value="" disabled selected>Please choose one</option>
                    <option value="BANK_ACCOUNT">Bank Account</option>
                    <option value="CREDIT_CARD">Credit Card</option>
                </select>
            </div>
            <div class="form-group" id="sub_type_container" style="display: none;">
                <label for="sub_type">Account Type:</label>
                <select id="sub_type" name="sub_type" class="form-control">
                    <option value="" disabled selected>Please choose one</option>
                    <option value="CHECKING">Checking</option>
                    <option value="SAVING">Saving</option>
                </select>
            </div>
            <button type="submit" class="btn btn-primary" disabled>Submit</button>
        </form>
    </div>





    <script>
        function showSubTypeAndEnableSubmit(selectedType) {
            var container = document.getElementById('sub_type_container');
            var submitButton = document.querySelector('#accountForm button[type="submit"]');

            if (selectedType === "BANK_ACCOUNT") {
                container.style.display = 'block';
                submitButton.disabled = true;
            } else if (selectedType === "CREDIT_CARD") {
                container.style.display = 'none';
                submitButton.disabled = false;
            } else {
                container.style.display = 'none';
                submitButton.disabled = true;
            }
        }

        // Additional JavaScript to handle enabling the submit button when a valid sub_type is selected
        document.getElementById('sub_type').addEventListener('change', function() {
            var submitButton = document.querySelector('#accountForm button[type="submit"]');
            if (this.value) {
                submitButton.disabled = false;
            }
        });
    </script>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
</body>

</html>